import cv2
import sys
import matplotlib.pyplot as plt


def parse_image(image):
    img = cv2.imread(image)

    histr = cv2.calcHist([img], [1], None, [256], [0, 256])
    plt.hist(histr)
    plt.show()


    color = ('b', 'g', 'r')
    for i, col in enumerate(color):
        histr = cv2.calcHist([img], [i], None, [256], [0, 256])
        plt.plot(histr, color=col)
        plt.xlim([0, 256])
    plt.show()


if __name__ == '__main__':
    print("deal image ", sys.argv[1])
    parse_image(sys.argv[1])
